package com.cai.servlet.msg;

import com.cai.dao.MsgDao;
import com.cai.dao.impl.MsgDaoImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

/**
 * @author RuoLi
 * 发送消息
 */
@WebServlet(name = "ServletSendMessage", value = "/SendMessage")
public class ServletSendMessage extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        MsgDao msgDao = new MsgDaoImpl();
        //        接收数据
        String sendUser = request.getParameter("sendUser");
        String sendText = request.getParameter("sendText");
        String returnUser = request.getParameter("returnUser");
        int count = msgDao.sendMsg(sendText, sendUser, returnUser);
        if (count != 0) {
            response.getWriter().println(1);
        } else {
            response.getWriter().println(0);
        }
    }
}
